/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CandidatoView.java
 *
 * Created on 06/12/2009, 05:57:20 PM
 */

package vista;

import controlador.ICandidatoController;
import modelo.ICandidato;
import modelo.ICandidatoModel;
/**
 *
 * @author LEONIC
 */
public class CandidatoView extends javax.swing.JFrame implements ICandidatoView {

    private ICandidatoModel model;
    private ICandidatoController controller;

    private CandidatoTableModel tableModel;
    private JPanelCandidato panelCandidato;

    /** Creates new form CandidatoView */
    public CandidatoView() {
        tableModel=new CandidatoTableModel();
        initComponents();

        this.panelCandidato=new JPanelCandidato(this);
        this.panelabajo.add(this.panelCandidato);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableCandidatos = new javax.swing.JTable();
        panelabajo = new javax.swing.JPanel();

        setTitle("Gestión de candidatos");

        jTableCandidatos.setModel(tableModel);
        jTableCandidatos.setUpdateSelectionOnSort(false);
        jTableCandidatos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableCandidatosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTableCandidatos);

        panelabajo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panelabajo.setLayout(new javax.swing.BoxLayout(panelabajo, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelabajo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE))
                .addGap(30, 30, 30))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(panelabajo, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTableCandidatosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableCandidatosMouseClicked
        CandidatoTableModel ctm=(CandidatoTableModel)this.jTableCandidatos.getModel();
        ICandidato proveedor=ctm.getRow(this.jTableCandidatos.getSelectedRow());
        this.panelCandidato.setProveedor(proveedor);
}//GEN-LAST:event_jTableCandidatosMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CandidatoView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableCandidatos;
    private javax.swing.JPanel panelabajo;
    // End of variables declaration//GEN-END:variables

    public ICandidatoController getController() {
        return controller;
    }

    public void setController(ICandidatoController controller) {
        this.controller=controller;
    }

    public ICandidatoModel getModel() {
        return model;
    }

    public void setModel(ICandidatoModel model) {
        this.model=model;
    }

    public void dataModelChanged() {
        refresh();
    }

    public void display() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                setVisible(true);
                refresh();
            }
        });
    }

    protected void refresh() {
        this.tableModel.setCandidatos(getModel().obtenerCandidato());
    }

    protected void fireNuevoCandidatoGesture(String dni, String nombre) {
        getController().nuevoCandidatoGesture(dni, nombre);
    }

    protected void fireActualizaCandidatoGesture(String dni, String nombre) {
        getController().actualizaCandidatoGesture(dni, nombre);
    }

    protected void fireBorraCandidatoGesture(String dni){
        getController().borraCandidatoGesture(dni);
    }

    protected void fireContratarCandidatoGesture(String dni,double salario,String rol,String usuario,String password){
        getController().ContratarCandidatoGesture(dni, salario, rol, usuario, password);
    }
}
